package com.kzd.gtboon.main.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.animation.Animation
import android.widget.*
import com.blankj.utilcode.util.ClipboardUtils
import com.blankj.utilcode.util.ToastUtils
import com.kzd.gtboon.R
import com.kzd.gtboon.custom.setOnClickAntiShakeListener
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AlphaConfig
import razerdp.util.animation.AnimationHelper

class GameExchangePopup(context: Context) : BasePopupWindow(context) {

    init {
        popupGravity = Gravity.CENTER
        setOverlayNavigationBar(false)
    }

    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_game_exchange)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        contentView.findViewById<ImageView>(R.id.ivGameExchangeClose).setOnClickAntiShakeListener {
            dismiss()
        }
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.IN)
            .toShow()
    }

    override fun onCreateDismissAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withAlpha(AlphaConfig.OUT)
            .toDismiss()
    }

    fun fillData(gameName: String, code: String): GameExchangePopup {
        contentView.findViewById<TextView>(R.id.tvGameExchangeName)
            .text = gameName
        contentView.findViewById<TextView>(R.id.tvGameExchangeCode)
            .text = "兑换码：${code}"
        contentView.findViewById<TextView>(R.id.tvGameExchangeCopy).setOnClickAntiShakeListener {
            ClipboardUtils.copyText(code)
            ToastUtils.showShort("兑换码:$code\t已复制，去联系客服吧！")
        }
        return this
    }

}